﻿using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Skyworth.CRM.Service.Entity;
using Skyworth.CRM.Service.IDAL;

namespace Skyworth.CRM.DAL
{
    public class FunctionDAL : SuperDataBase, IFunctionDAL
    {
        public DataTable Query(string strWhere)
        {
            try
            {
                string sql = "SELECT * FROM [T_SYS_Function]  ";
                sql += strWhere;
                DataSet ds = DB.ExecuteDataSet(CommandType.Text, sql);
                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable GetPagesFunction(int pageId)
        {
            try
            {
                string sql = "select tsf.FunctionID,tsf.FunctionName,ISNULL(tsfm.Flag,0) as flag from T_SYS_Function as tsf"
                    + " left join T_SYS_FunctionModules as tsfm on tsf.FunctionID=tsfm.FunctionID and tsfm.ModuleID = @ModuleID";
                DbCommand cmd = DB.GetSqlStringCommand(sql);
                DB.AddInParameter(cmd, "@ModuleID", DbType.Int32, pageId);
                return DB.ExecuteDataSet(cmd).Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        

        public DataTable Query(string strWhere, Hashtable parameter)
        {
            throw new NotImplementedException();
        }
    }
} 